package com.qs.eggs.view.fragment;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.SearchView;
import android.util.TypedValue;
import android.view.View.OnClickListener;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.Zxing.Demo.CaptureActivity;
import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.listener.OnItemClickListener;
import com.daimajia.slider.library.Animations.DescriptionAnimation;
import com.daimajia.slider.library.SliderLayout;
import com.daimajia.slider.library.SliderTypes.BaseSliderView;
import com.daimajia.slider.library.SliderTypes.DefaultSliderView;
import com.facebook.drawee.view.SimpleDraweeView;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.qs.eggs.Constants;
import com.qs.eggs.MainActivity;
import com.qs.eggs.R;
import com.qs.eggs.account.LoginActivity;
import com.qs.eggs.adapter.PocAdapter;
import com.qs.eggs.adapter.PoiAdapter;
import com.qs.eggs.adapter.PopAdapter;
import com.qs.eggs.adapter.PosAdapter;
import com.qs.eggs.adapter.PotAdapter;
import com.qs.eggs.api.HttpApi;
import com.qs.eggs.base.fragment.BaseFragment;

import com.qs.eggs.refresh.utils.TDevice;
import com.qs.eggs.utils.SpacesItemDecoration;
import com.qs.eggs.view.activity.GonggaoActivity;
import com.qs.eggs.view.activity.JifenActivity;
import com.qs.eggs.view.activity.LuckyActivity;
import com.qs.eggs.view.activity.PayMethodActivity;
import com.qs.eggs.view.activity.SortActivity;
import com.qs.eggs.view.activity.SubmitLoginActivity;
import com.qs.eggs.view.prodetail.activity.ProDetailActivity;
import com.qs.eggs.widgets.custom.GridViewForScrollView;
import com.qs.eggs.widgets.custom.NetworkImageHolderView;
import com.qs.eggs.widgets.custom.PullToRefreshView;
import com.squareup.picasso.Picasso;
import com.sunfusheng.marqueeview.MarqueeView;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Response;

public class PrimaryFragment extends BaseFragment implements OnClickListener,PullToRefreshView.OnHeaderRefreshListener, PullToRefreshView.OnFooterRefreshListener{
    private PullToRefreshView mPullToRefreshView;
    private  ImageView erweima,imageView1,imageView2,imageView3,imageView4,imageView5;
    private ConvenientBanner sliderLayout;
    private LinearLayout layout1,layout2,layout3,layout4,layout5;
    private RecyclerView gridView0,gridView1,gridView2,gridView3;
    private GridViewForScrollView gridView4;
    private RelativeLayout tehuimore,huodongmore,remaimore,likemore,jingpinmore,jifen,choujiang;
    private List<Map<String, Object>> tehui = null;
    private List<Map<String, Object>> taocan = null;
    private List<Map<String, Object>> hot = null;
    private List<Map<String, Object>> like = null;
    private List<Map<String, Object>> putong = null;
    private String url1,url2,url3,url4,url5;
    private SimpleDraweeView simpleDraweeView;
    private String proid1,proid2,proid3,proid4,proid5;
    private TextView textView1,textView2,textView3,textView4,textView5;
    private EditText mSearch;
    private TextView icSearch;
    PoiAdapter mAdapter;
    PopAdapter pAdapter;
    PosAdapter sAdapter;
    PotAdapter tAdapter;
    PocAdapter cAdapter;
    MarqueeView marqueeView;
    private int spacingInPixels=30;
    private int REQUEST_CODE=1002;
    int bwidth = 720;
    int bHeight = 576;
    private List<String> networkImages;
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_primary;
    }

    @Override
    protected void initWidget(View root) {
        super.initWidget(root);
        mPullToRefreshView =findView(R.id.main_pull_refresh_view);
        erweima = findView(R.id.erweima);
        mSearch = findView(R.id.poi_et_search);
        sliderLayout = findView(R.id.convenientBanner);
        icSearch=findView(R.id.img_search);
        layout1=findView(R.id.layout1);
        layout2=findView(R.id.layout2);
        layout3=findView(R.id.layout3);
        layout4=findView(R.id.layout4);
        layout5=findView(R.id.layout5);
        jifen=findView(R.id.jifen);
        choujiang=findView(R.id.choujiang);
        simpleDraweeView=findView(R.id.simpledraweevew);
        imageView1=findView(R.id.imageView1);
        imageView2=findView(R.id.imageView2);
        imageView3=findView(R.id.imageView3);
        imageView4=findView(R.id.imageView4);
        imageView5=findView(R.id.imageView5);

        textView1=findView(R.id.textView1);
        textView2=findView(R.id.textView2);
        textView3=findView(R.id.textView3);
        textView4=findView(R.id.textView4);
        textView5=findView(R.id.textView5);

        tehuimore=findView(R.id.rl1);
        huodongmore=findView(R.id.rl2);
        remaimore=findView(R.id.rl3);
        likemore=findView(R.id.rl4);
        jingpinmore=findView(R.id.rl5);

        gridView0=findView(R.id.GridView0);
        gridView1=findView(R.id.GridView1);
        gridView2=findView(R.id.GridView2);
        gridView3=findView(R.id.GridView3);
        gridView4=findView(R.id.GridView4);
        marqueeView =findView(R.id.marqueeView);

        erweima.setOnClickListener(this);
        icSearch.setOnClickListener(this);
        layout1.setOnClickListener(this);
        layout2.setOnClickListener(this);
        layout3.setOnClickListener(this);
        layout4.setOnClickListener(this);
        layout5.setOnClickListener(this);
        simpleDraweeView.setOnClickListener(this);

        tehuimore.setOnClickListener(this);
        huodongmore.setOnClickListener(this);
        remaimore.setOnClickListener(this);
        likemore.setOnClickListener(this);
        jingpinmore.setOnClickListener(this);
        erweima.setOnClickListener(this);
        mSearch.setOnClickListener(this);

        jifen.setOnClickListener(this);
        choujiang.setOnClickListener(this);

        mPullToRefreshView =findView(R.id.main_pull_refresh_view);
        mPullToRefreshView.setOnHeaderRefreshListener(this);
        mPullToRefreshView.setOnFooterRefreshListener(this);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);

        LinearLayoutManager linearLayoutManager1 = new LinearLayoutManager(getActivity());
        linearLayoutManager1.setOrientation(LinearLayoutManager.HORIZONTAL);

        LinearLayoutManager linearLayoutManager2 = new LinearLayoutManager(getActivity());
        linearLayoutManager2.setOrientation(LinearLayoutManager.HORIZONTAL);

        LinearLayoutManager linearLayoutManager3 = new LinearLayoutManager(getActivity());
        linearLayoutManager3.setOrientation(LinearLayoutManager.HORIZONTAL);
        gridView0.setLayoutManager(linearLayoutManager);
        gridView1.setLayoutManager(linearLayoutManager1);
        gridView2.setLayoutManager(linearLayoutManager2);
        gridView3.setLayoutManager(linearLayoutManager3);
        initImageLoader();
        getSpecial();
        getFenlei();
        getGonggao();
        getTehui();
        getHuodong();
        getXinpin();
        getHot();
        getLike();
        getPutong();
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.erweima:
                HttpApi.cheakIsLogin(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        if(s.equals("\"true\"")){
//                            Intent intent = new Intent(getContext(), CaptureActivity.class);
//                            startActivityForResult(intent, REQUEST_CODE);
                            Intent intent = new Intent(getActivity(), CaptureActivity.class);
                            startActivity(intent);
                        }else {
                            LoginActivity.show(getContext());
                        }
                    }
                });
//
                break;
            case R.id.img_search:
                if(mSearch.getText().length()==0){
                    Toast.makeText(getContext(),"请输入搜索内容",Toast.LENGTH_SHORT).show();
                    return;
                }
                Intent sort=new Intent(getActivity(),SortActivity.class);
                sort.putExtra("biaoshi","search");
                sort.putExtra("pronameLIKE",mSearch.getText().toString().trim());
                startActivity(sort);
                break;
            case R.id.layout1:
                //   TMD，超强大脑，fuck
                MainActivity.mNavBar.select(1);
                CategoryFragment.fromPrimary(0);
                CategoryFragment.flag="1";

                break;
            case R.id.layout2:
                MainActivity.mNavBar.select(1);
                CategoryFragment.fromPrimary(1);
                CategoryFragment.flag="1";
                break;
            case R.id.layout3:
                MainActivity.mNavBar.select(1);
                CategoryFragment.fromPrimary(2);
                CategoryFragment.flag="1";
                break;
            case R.id.layout4:
                MainActivity.mNavBar.select(1);
                CategoryFragment.fromPrimary(3);
                CategoryFragment.flag="1";
                break;
            case R.id.layout5:
                MainActivity.mNavBar.select(1);
                CategoryFragment.fromPrimary(4);
                CategoryFragment.flag="1";
                break;
            case R.id.rl1:
                Intent a=new Intent(getActivity(),SortActivity.class);
                a.putExtra("biaoshi","special");
                startActivity(a);
                break;
            case R.id.rl2:
                Intent b=new Intent(getActivity(),SortActivity.class);
                b.putExtra("biaoshi","activity");
                startActivity(b);
                break;
            case R.id.rl3:
                Intent c=new Intent(getActivity(),SortActivity.class);
                c.putExtra("biaoshi","hot");
                startActivity(c);
                break;
            case R.id.rl4:
                Intent d =new Intent(getActivity(),SortActivity.class);
                d.putExtra("biaoshi","like");
                startActivity(d);
                break;
            case R.id.rl5:
                Intent e=new Intent(getActivity(),SortActivity.class);
                e.putExtra("biaoshi","product");
                startActivity(e);
                break;
            case R.id.simpledraweevew:
                Intent f=new Intent(getActivity(),SortActivity.class);
                f.putExtra("biaoshi","new");
                startActivity(f);
                break;
            case R.id.jifen:
                Intent intent=new Intent(getActivity(),JifenActivity.class);
                startActivity(intent);
                break;
            case R.id.choujiang:
                Intent intent1=new Intent(getActivity(),LuckyActivity.class);
                startActivity(intent1);
                break;
        }
    }
    //轮播图
    private void getSpecial() {
        OkGo.post(Constants.URL_BASE+"mall/showproduct?action=subjectPic")
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        try {
                            final JSONArray jsonArray = new JSONArray(s);
                            final List<String> list = new ArrayList<>();
                            String[] images=new String[jsonArray.length()];
                            for ( int i = 0; i < jsonArray.length(); i++) {
                                //准备好要显示的数据
                                images[i]=Constants.URL_BASE + jsonArray.getJSONObject(i).getString("folder") + jsonArray.getJSONObject(i).getString("autoname")+"";
                                list.add(jsonArray.getJSONObject(i).getString("id"));
                                networkImages= Arrays.asList(images);
                                int width =(int)TDevice.getScreenWidth();
                                int height = width * bHeight / bwidth;
                                ViewGroup.LayoutParams para = sliderLayout.getLayoutParams();
                                para.height = height;
                                sliderLayout.setLayoutParams(para);
                                sliderLayout.setPages(new CBViewHolderCreator<NetworkImageHolderView>() {
                                    @Override
                                    public NetworkImageHolderView createHolder() {
                                        return new NetworkImageHolderView();
                                    }
                                },networkImages);
                                sliderLayout.setOnItemClickListener(new OnItemClickListener() {
                                    @Override
                                    public void onItemClick(int position) {
                                        Intent intent=new Intent(getActivity(),SortActivity.class);
                                        intent.putExtra("specialid",list.get(position));
                                        intent.putExtra("biaoshi","benner");
                                        startActivity(intent);
                                    }
                                });
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
    }
    //分类
    private void getFenlei(){

        OkGo.post(Constants.URL_BASE+"mall/showproduct?action=getProductTress")
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        try {
                            JSONArray jsonArray = new JSONArray(s);
                            for (int i = 0; i < jsonArray.length(); i++) {
                                url1=Constants.URL_BASE+jsonArray.getJSONObject(0).getString("folder")+jsonArray.getJSONObject(0).getString("autoname");
                                url2=Constants.URL_BASE+jsonArray.getJSONObject(1).getString("folder")+jsonArray.getJSONObject(1).getString("autoname");
                                url3=Constants.URL_BASE+jsonArray.getJSONObject(2).getString("folder")+jsonArray.getJSONObject(2).getString("autoname");
                                url4=Constants.URL_BASE+jsonArray.getJSONObject(3).getString("folder")+jsonArray.getJSONObject(3).getString("autoname");
                                url5=Constants.URL_BASE+jsonArray.getJSONObject(4).getString("folder")+jsonArray.getJSONObject(4).getString("autoname");

                                proid1 = jsonArray.getJSONObject(0).getString("id");
                                proid2 =  jsonArray.getJSONObject(1).getString("id");
                                proid3 =  jsonArray.getJSONObject(2).getString("id");
                                proid4 =  jsonArray.getJSONObject(3).getString("id");
                                proid5 =  jsonArray.getJSONObject(4).getString("id");

                                textView1.setText(jsonArray.getJSONObject(0).getString("name"));
                                textView2.setText(jsonArray.getJSONObject(1).getString("name"));
                                textView3.setText(jsonArray.getJSONObject(2).getString("name"));
                                textView4.setText(jsonArray.getJSONObject(3).getString("name"));
                                textView5.setText(jsonArray.getJSONObject(4).getString("name"));
                                Picasso.with(getActivity()).load(url1).into(imageView1);
                                Picasso.with(getActivity()).load(url2).into(imageView2);
                                Picasso.with(getActivity()).load(url3).into(imageView3);
                                Picasso.with(getActivity()).load(url4).into(imageView4);
                                Picasso.with(getActivity()).load(url5).into(imageView5);
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });

    }
    //特惠产品
    private void getTehui(){
        Map<String, String> map = new HashMap<>();
        map.put("biaoshi","special");
        Gson gson = new Gson();
        String str = gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"mall/showproduct?action=loadProductInfo")
                .params("params",str)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        JSONArray jsonArray=null;
                        JSONObject jsonObject=null;
                        try {
                            tehui=new ArrayList<>();
                            jsonArray=new JSONArray(s);
                            for (int i=0;i<jsonArray.length();i++){
                                jsonObject=jsonArray.getJSONObject(i);
                                Map<String,Object> map=new HashMap<>();
                                map.put("proid",jsonObject.getString("id"));
                                map.put("prono",jsonObject.getString("prono"));
                                map.put("proname",jsonObject.getString("proname"));
                                map.put("autoname",jsonObject.getString("autoname"));
                                map.put("saleprice",jsonObject.getString("saleprice"));
                                map.put("type",jsonObject.getString("type"));
                                map.put("specification",jsonObject.getString("specification"));
                                tehui.add(map);
                            }

                            mAdapter = new PoiAdapter(getActivity(), tehui);
//                            gridView0.addItemDecoration(new SpacesItemDecoration(spacingInPixels));
                            gridView0.setAdapter(mAdapter);
                            mAdapter.setOnItemClickListener(new PoiAdapter.OnItemClickListener() {
                                @Override
                                public void onItemClick(View view, int position) {
                                    Intent intent=new Intent(getActivity(),ProDetailActivity.class);
                                    intent.putExtra("proid",tehui.get(position).get("proid").toString());
                                    intent.putExtra("type",tehui.get(position).get("type").toString());
                                    startActivity(intent);
                                }
                            });

                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
    }
    //活动套餐
    private void getHuodong(){
        Map<String, String> map = new HashMap<>();
        map.put("biaoshi","activity");
        Gson gson = new Gson();
        String str = gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"mall/showproduct?action=loadProductInfo")
                .params("params",str)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        System.out.print("活动套餐=="+s);
                        JSONArray jsonArray=null;
                        JSONObject jsonObject=null;
                        try {
                            taocan=new ArrayList<>();
                            jsonArray=new JSONArray(s);
                            for (int i=0;i<jsonArray.length();i++){
                                jsonObject=jsonArray.getJSONObject(i);
                                Map<String,Object> map=new HashMap<>();
                                map.put("proid",jsonObject.getString("id"));
                                map.put("proname",jsonObject.getString("proname"));
                                map.put("autoname",jsonObject.getString("autoname"));
                                map.put("saleprice",jsonObject.getString("saleprice"));
                                map.put("type",jsonObject.getString("type"));
                                taocan.add(map);
                            }
                            pAdapter = new PopAdapter(getActivity(), taocan);
                            //gridView1.addItemDecoration(new SpacesItemDecoration(spacingInPixels));
                            gridView1.setAdapter(pAdapter);
                            pAdapter.setOnItemClickListener(new PopAdapter.OnItemClickListener() {
                                @Override
                                public void onItemClick(View view, int position) {
                                    Intent intent=new Intent(getActivity(),ProDetailActivity.class);
                                    intent.putExtra("proid",taocan.get(position).get("proid").toString());
                                    intent.putExtra("type",taocan.get(position).get("type").toString());
                                    startActivity(intent);
                                }
                            });

                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
    }
    //热卖产品
    private  void getHot(){
        Map<String, String> map = new HashMap<>();
        map.put("biaoshi","hot");
        Gson gson = new Gson();
        String str = gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"mall/showproduct?action=loadProductInfo")
                .params("params",str)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        JSONArray jsonArray=null;
                        JSONObject jsonObject=null;
                        try {
                            hot=new ArrayList<>();
                            jsonArray=new JSONArray(s);
                            for (int i=0;i<jsonArray.length();i++){
                                jsonObject=jsonArray.getJSONObject(i);
                                Map<String,Object> map=new HashMap<>();
                                map.put("proid",jsonObject.getString("id"));
                                map.put("prono",jsonObject.getString("prono"));
                                map.put("proname",jsonObject.getString("proname"));
                                map.put("autoname",jsonObject.getString("autoname"));
                                map.put("saleprice",jsonObject.getString("saleprice"));
                                map.put("type",jsonObject.getString("type"));
                                map.put("specification",jsonObject.getString("specification"));
                                hot.add(map);
                            }
                            sAdapter = new PosAdapter(getActivity(), hot);
                            //gridView2.addItemDecoration(new SpacesItemDecoration(spacingInPixels));
                            gridView2.setAdapter(sAdapter);
                            sAdapter.setOnItemClickListener(new PosAdapter.OnItemClickListener() {
                                @Override
                                public void onItemClick(View view, int position) {
                                    Intent intent=new Intent(getActivity(),ProDetailActivity.class);
                                    intent.putExtra("proid",hot.get(position).get("proid").toString());
                                    intent.putExtra("type",hot.get(position).get("type").toString());
                                    startActivity(intent);
                                }
                            });
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
    }
    //猜你喜欢
    private void getLike(){
        Map<String, String> map = new HashMap<>();
        map.put("biaoshi","like");
        Gson gson = new Gson();
        String str = gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"mall/showproduct?action=loadProductInfo")
                .params("params",str)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        System.out.print("猜你喜欢=="+s);
                        JSONArray jsonArray=null;
                        JSONObject jsonObject=null;
                        try {
                            like=new ArrayList<>();
                            jsonArray=new JSONArray(s);
                            for (int i=0;i<jsonArray.length();i++){
                                jsonObject=jsonArray.getJSONObject(i);
                                Map<String,Object> map=new HashMap<>();
                                map.put("proid",jsonObject.getString("id"));
                                map.put("prono",jsonObject.getString("prono"));
                                map.put("proname",jsonObject.getString("proname"));
                                map.put("autoname",jsonObject.getString("autoname"));
                                map.put("saleprice",jsonObject.getString("saleprice"));
                                map.put("type",jsonObject.getString("type"));
                                map.put("specification",jsonObject.getString("specification"));
                                like.add(map);
                            }
                            tAdapter = new PotAdapter(getActivity(), like);
                            //gridView3.addItemDecoration(new SpacesItemDecoration(spacingInPixels));
                            gridView3.setAdapter(tAdapter);
                            tAdapter.setOnItemClickListener(new PotAdapter.OnItemClickListener() {
                                @Override
                                public void onItemClick(View view, int position) {
                                    Intent intent=new Intent(getActivity(),ProDetailActivity.class);
                                    intent.putExtra("proid",like.get(position).get("proid").toString());
                                    intent.putExtra("type",like.get(position).get("type").toString());
                                    startActivity(intent);
                                }
                            });
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });

    }
    //普通精品
    private void getPutong(){
        Map<String, String> map = new HashMap<>();
        map.put("biaoshi","product");
        Gson gson = new Gson();
        String str = gson.toJson(map);
        OkGo.post(Constants.URL_BASE+"mall/showproduct?action=loadProductInfo")
                .params("params",str)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        System.out.print("普通精品=="+s);
                        JSONArray jsonArray=null;
                        JSONObject jsonObject=null;
                        try {
                            putong=new ArrayList<>();
                            jsonArray=new JSONArray(s);
                            for (int i=0;i<4;i++){
                                jsonObject=jsonArray.getJSONObject(i);
                                Map<String,Object> map=new HashMap<>();
                                map.put("proid",jsonObject.getString("id"));
                                map.put("prono",jsonObject.getString("prono"));
                                map.put("proname",jsonObject.getString("proname"));
                                map.put("autoname",jsonObject.getString("autoname"));
                                map.put("saleprice",jsonObject.getString("saleprice"));
                                map.put("type",jsonObject.getString("type"));
                                map.put("specification",jsonObject.getString("specification"));
                                putong.add(map);
                            }
                            cAdapter = new PocAdapter(getActivity(), putong);
                            gridView4.setAdapter(cAdapter);
                            gridView4.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                @Override
                                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                    Intent intent=new Intent(getActivity(),ProDetailActivity.class);
                                    intent.putExtra("proid",putong.get(position).get("proid").toString());
                                    intent.putExtra("type",putong.get(position).get("type").toString());
                                    startActivity(intent);
                                }
                            });

                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });

    }

    //新品推荐
    private void getXinpin(){
        OkGo.post(Constants.URL_BASE+"mall/showproduct?action=indexPic")
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        System.out.print("新品推荐=="+s);
                        try {
                            String imageUrls="";
                            JSONArray jsonArray = new JSONArray(s);
                            for (int i = 0; i < jsonArray.length(); i++) {
                                if (jsonArray.getJSONObject(i).getString("status").equals("new")){
                                    imageUrls=Constants.URL_BASE+jsonArray.getJSONObject(i).getString("folder")+jsonArray.getJSONObject(i).getString("autoname");
                                }
                            }
                            simpleDraweeView.setImageURI(imageUrls);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });

    }

    //公告信息
    private void getGonggao(){
        OkGo.post(Constants.URL_BASE+"notice?action=getNotice")
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        try {
                            final JSONArray jsonArray = new JSONArray(s);
                            for (int i = 0; i < jsonArray.length(); i++) {
                                List<String> info = new ArrayList<>();
                                final List<String> idList = new ArrayList<>();
                                idList.add(jsonArray.getJSONObject(i).getString("id"));
                                info.add(jsonArray.getJSONObject(i).getString("name"));
                                for (int j = 0; j < info.size(); j++) {
                                    marqueeView.startWithText(info.get(j));
                                    final int finalI = j;
                                    marqueeView.setOnItemClickListener(new MarqueeView.OnItemClickListener() {
                                        @Override
                                        public void onItemClick(int position, TextView textView) {
                                           // Toast.makeText(getActivity(), textView.getText()+"", Toast.LENGTH_SHORT).show();
                                            Intent intent=new Intent(getActivity(), GonggaoActivity.class);
                                            intent.putExtra("id", idList.get(finalI));
                                            startActivity(intent);
                                        }
                                    });
                                }

                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
    }

//    @Override
//    public void onActivityResult(int requestCode, int resultCode, Intent data) {
//        super.onActivityResult(requestCode, resultCode, data);
//        if (requestCode == REQUEST_CODE) {
//            //处理扫描结果（在界面上显示）
//            if (null != data) {
//                Bundle bundle = data.getExtras();
//                if (bundle == null) {
//                    return;
//                }
//                if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS) {
//                    final String result = bundle.getString(CodeUtils.RESULT_STRING);
//
//
//                    OkGo.post(Constants.URL_BASE + "personal?action=getPersonalInfo")
//                            .execute(new StringCallback() {
//                                @Override
//                                public void onSuccess(String s, Call call, Response response) {
//                                    try {
//                                        String accountname="";
//                                        String password="";
//                                        JSONArray jsonArray = new JSONArray(s);
//                                        for (int i = 0; i < jsonArray.length(); i++) {
//                                            accountname=jsonArray.getJSONObject(i).getString("accountname");
//                                            password=jsonArray.getJSONObject(i).getString("password");
//                                        }
//                                        HashMap<String,String> map=new HashMap<String, String>();
//                                        map.put("accountname",accountname);
//                                        map.put("password",password);
//                                        map.put("uuid",result);
//                                        Gson gson=new Gson();
//                                        String params=gson.toJson(map);
//                                        final String finalPassword = password;
//                                        final String finalAccountname = accountname;
//                                        OkGo.post(Constants.URL_BASE+"mallLogin?action=saomaMallLogin")
//                                                .params("params",params)
//                                                .execute(new StringCallback() {
//                                                    @Override
//                                                    public void onSuccess(String s, Call call, Response response) {
//                                                        System.out.print("信息=="+s);
//                                                        if (s.equals("\"false\"")){
//                                                            Toast.makeText(getContext(),"用户不存在",Toast.LENGTH_LONG).show();
//                                                        }else{
//                                                            Intent intent=new Intent(getContext(),SubmitLoginActivity.class);
//                                                            intent.putExtra("accountname", finalAccountname);
//                                                            intent.putExtra("password", finalPassword);
//                                                            intent.putExtra("uuid",result);
//                                                            startActivity(intent);
//                                                        }
//                                                    }
//                                                });
//                                    } catch (Exception e) {
//                                        e.printStackTrace();
//                                    }
//                                }
//                            });
//
//                } else if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_FAILED) {
//                    Toast.makeText(getContext(), "解析二维码失败", Toast.LENGTH_LONG).show();
//                }
//            }
//        }
//    }

    @Override
    public void onFooterRefresh(PullToRefreshView view) {
        mPullToRefreshView.postDelayed(new Runnable() {

            @Override
            public void run() {
                handler1.sendEmptyMessage(1);
                getSpecial();
                getFenlei();
                getGonggao();
                getTehui();
                getHuodong();
                getXinpin();
                getHot();
                getLike();
                getPutong();
                mPullToRefreshView.onFooterRefreshComplete();
            }
        }, 500);
    }

    @Override
    public void onHeaderRefresh(PullToRefreshView view) {
        mPullToRefreshView.postDelayed(new Runnable() {

            @Override
            public void run() {
                handler1.sendEmptyMessage(1);
                getSpecial();
                getFenlei();
                getGonggao();
                getTehui();
                getHuodong();
                getXinpin();
                getHot();
                getLike();
                getPutong();
                mPullToRefreshView.onHeaderRefreshComplete();
            }
        }, 500);

    }
	/*-----------刷新接口方法实现-------	*/

    Handler handler1 = new Handler() {
        public void handleMessage(Message message) {
            super.handleMessage(message);
            mPullToRefreshView.onFooterRefreshComplete();

        }

    };
    //初始化网络图片缓存库
    private void initImageLoader(){
        //网络图片例子,结合常用的图片缓存库UIL,你可以根据自己需求自己换其他网络图片库
        DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder().
                showImageForEmptyUri(R.mipmap.ic_default_adimage)
                .cacheInMemory(true).cacheOnDisk(true).build();

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                getActivity().getApplicationContext()).defaultDisplayImageOptions(defaultOptions)
                .threadPriority(Thread.NORM_PRIORITY - 2)
                .denyCacheImageMultipleSizesInMemory()
                .diskCacheFileNameGenerator(new Md5FileNameGenerator())
                .tasksProcessingOrder(QueueProcessingType.LIFO).build();
        ImageLoader.getInstance().init(config);
    }
    // 开始自动翻页
    @Override
    public void onResume() {
        super.onResume();
        //开始自动翻页
        sliderLayout.startTurning(3000);
    }

    // 停止自动翻页
    @Override
    public void onPause() {
        super.onPause();
        //停止翻页
        sliderLayout.stopTurning();
    }

}
